//
//  ProjectCell.swift
//  JianTingSwift
//
//  Created by zhibao on 2024/11/20.
//

import UIKit

@objc class ProjectCell: UITableViewCell {
    var imgView:UIImageView!
    var newIconView:UIImageView!
    var nameLabel:UILabel!
    var priceLabel:UILabel!
    var dayLabel:UILabel!
    var baoYouLabel:UILabel!
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        self.selectionStyle = .none
        self.backgroundColor = UIColor.clear
        
        let bgview = UIView()
        bgview.backgroundColor = MYColor.color(withHexString: "f2f2f2")
        self.contentView.addSubview(bgview)
        bgview.layer.cornerRadius = pixw(p:15)
        bgview.snp.makeConstraints { make in
            make.left.equalTo(pixw(p:15));
            make.top.equalTo(pixw(p:10));
            make.right.equalTo(pixw(p:-15));
            make.bottom.equalTo(0);
        }
        
        imgView = UIImageView(image: UIImage(named: "h_project"))
        imgView.contentMode = .scaleAspectFit
        bgview.addSubview(imgView)
        imgView.snp.makeConstraints { make in
            make.left.equalTo(pixw(p: 20))
            make.top.equalTo(pixw(p: 10))
            make.bottom.equalTo(pixw(p: -10))
            make.width.height.equalTo(pixw(p: 80))
        }
        
        newIconView = UIImageView(image: UIImage(named: "h_5"))
        imgView.addSubview(newIconView)
        newIconView.snp.makeConstraints { make in
            make.left.top.equalTo(imgView)
            make.width.equalTo(pixw(p: 50))
            make.height.equalTo(pixw(p: 18))
        }
        
        nameLabel = UILabel()
        nameLabel.text = "荣耀手环5 陨石黑 智能 运动"
        nameLabel.font = MY_SCALE_MediumFONT(15)
        nameLabel.textColor = MYBlock
        bgview.addSubview(nameLabel)
        nameLabel.snp.makeConstraints { make in
            make.left.equalTo(imgView.snp.right).offset(pixw(p: 10));
            make.top.equalTo(imgView);
            make.right.equalTo(bgview).offset(pixw(p:-15));
        }
        
        
        let qianPriceLabel = UILabel()
        qianPriceLabel.text = "¥"
        qianPriceLabel.font = MY_SCALE_LightFONT(12)
        qianPriceLabel.textColor = MYRed
        bgview.addSubview(qianPriceLabel)
        qianPriceLabel.snp.makeConstraints { make in
            make.left.equalTo(nameLabel);
            make.top.equalTo(nameLabel.snp.bottom).offset(pixw(p: 10));
        }
        
        priceLabel = UILabel()
        priceLabel.text = "27"
        priceLabel.font = MY_SCALE_BoldFont(20)
        priceLabel.textColor = MYRed
        bgview.addSubview(priceLabel)
        priceLabel.snp.makeConstraints { make in
            make.left.equalTo(qianPriceLabel.snp.right).offset(0);
            make.bottom.equalTo(qianPriceLabel);
        }
        
        let cpriceLabel = UILabel()
        cpriceLabel.text = "/天"
        cpriceLabel.font = MY_SCALE_LightFONT(12)
        cpriceLabel.textColor = MYRed
        bgview.addSubview(cpriceLabel)
        cpriceLabel.snp.makeConstraints { make in
            make.left.equalTo(priceLabel.snp.right).offset(0);
            make.bottom.equalTo(qianPriceLabel);
        }
        
        baoYouLabel = UILabel()
        baoYouLabel.text = "   vip独享:包邮包送   "
        baoYouLabel.font = MY_SCALE_RegularFONT(11)
        baoYouLabel.layer.cornerRadius = pixw(p: 3)
        baoYouLabel.layer.masksToBounds = true
        baoYouLabel.backgroundColor = MYColor.color(withHexString: "#E95A27", alpha: 0.1)
        baoYouLabel.textColor = MYRed
        bgview.addSubview(baoYouLabel)
        baoYouLabel.snp.makeConstraints { make in
            make.left.equalTo(cpriceLabel.snp.right).offset(pixw(p: 2));
            make.centerY.equalTo(cpriceLabel);
            make.height.equalTo(pixw(p: 18))
        }
        
        dayLabel = UILabel()
        dayLabel.text = "5天起租"
        dayLabel.font = MY_SCALE_RegularFONT(12)
        dayLabel.textColor = MYColor.color(withHexString: "#999999")
        bgview.addSubview(dayLabel)
        dayLabel.snp.makeConstraints { make in
            make.left.equalTo(nameLabel);
            make.bottom.equalTo(imgView);
        }
    }
    
    /// 更新数据
    /// - Parameters:
    ///   - name: 名字带后缀
    ///   - docum: 路径
    ///   - type: 类型
    func updata(dic:[String:String]) {
        nameLabel.text = dic["name"]
        priceLabel.text = dic["price"]
        dayLabel.text = "\(String(describing: dic["day"] ?? ""))天起租"
        baoYouLabel.text = "   vip独享:\(String(describing: dic["vip"] ?? ""))   "
        imgView.image = UIImage(named: dic["img"] ?? "")
        newIconView.image = UIImage(named: dic["new"] ?? "")
        if dic["new"] == "" {
            newIconView.isHidden = true
        }else{
            newIconView.isHidden = false
        }
        
    }

    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}

